<?php

namespace App\model;

use Illuminate\Database\Eloquent\Model;
use App\model\mongodb;
use DB;

class pushDataToDatabase extends Model
{
    //
    public function __construct(){
    	$this->push = new \App\model\dataCore();
    }

    public function pushTheData($classify, $data, $collection = ''){
    	switch ($classify) {
    		case 'user':
    			return $this->push->pushTheData('sots_user', $data);
    			break;
    		case 'nots':

    			$mongodb = mongodb::connectionMongodb('dialog',$collection);
                $result = $mongodb->insert($data);
                $count = count($mongodb->get());
                $date = time();
                
                if ($count) {
                    $mongodb->where('_id', '1')->update(['count'=>$count]);
                }else{
                    $mongodb->where('_id', '1')->update(['count'=>$count,'time'=>$date,'type'=>$data['type'],'status'=>1], ['upsert'=>true]);
                }

                return $result;
                
    			break;
    		case 'invitation':
    			return $this->push->pushTheData('sots_invitation', $data);
    			break;
    		default:
    			return $this->push->pushTheData('sots_topic', $data);
    			break;
    	}
    }

}
